package br.com.k19.controle;

import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.event.ActionEvent;

@ManagedBean
public class BotaoBean {

	public void sorteiaBotao(ActionEvent event) {
		UIComponent form = event.getComponent().getParent();

		UIComponent botao1 = form.findComponent("botao1");
		UIComponent botao2 = form.findComponent("botao2");
		UIComponent botao3 = form.findComponent("botao3");

		botao1.getAttributes().put("disabled", true);
		botao2.getAttributes().put("disabled", true);
		botao3.getAttributes().put("disabled", true);

		Double random = Math.random();

		if (random < 1.0 / 3.0)
			botao1.getAttributes().put("disabled", false);
		else if (random < 2.0 / 3.0)
			botao2.getAttributes().put("disabled", false);
		else
			botao3.getAttributes().put("disabled", false);
	}
}
